#!/usr/bin/perl 
use strict;

use DBI;
use CGI;
use TTraker;

my $dbh;

initialize_dbi();
print_header();

my $form_ref = parse_input();

my %FORM_DATA = %$form_ref; 

my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job_id = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $activity = $FORM_DATA{'activity'};
my $sent_from = $ENV{'REMOTE_ADDR'};

my $now = get_local_time($loc);

my @active = qw (blank start finish log continue lunch break leave);
print_log ("$activity,$active[$activity],trak_02_activiyty.pl,$num,$name");

if ($activity == 1 ) {
	csr_work_screen_from_pm ($num, $name, $job_id, $loc, "NONE");	
# } elsif ($activity == 5 ) {
#   lunch_time ($num, $name, $job_id, $loc, $activity);
# } elsif ($activity == 6 ) {
#   break_time ($num, $name, $job_id, $loc, $activity);
} elsif ($activity == 7 ) {
   leave_work ($num, $name, $job_id, $loc, $activity);
} else {
   print "ACTIVITY ERROR!<br/>";
}

db_disconnect();

############### SUBROUTINES FOLLOW ###############


sub leave_work 
{
	my $num = $_[0];
	my $name = $_[1];
	my $job_id = $_[2];
	my $loc = $_[3];
	my $activity = $_[4];
	# print "$num, $name, $job_id, $loc, $activity <br/>";
	log_out_of_work ($num, $now);
	end_system_time ($num, "ALL", $now);
	update_system_elapsed_time ($num );
	clear_hold_jobs($num);
	log_in_screen_from_pm ();
}

sub lunch_time
{
	my $num = $_[0];
	my $name = $_[1];
	my $job_id = $_[2];
	my $loc = $_[3];
	my $activity = $_[4];
	# print "$num, $name, $job_id, $loc, $activity <br/>";
	log_lunch_break ($num, $now); 
	end_system_time ($num, "ALL", $now);
	update_system_elapsed_time ($num );
	log_in_screen_from_pm ();
	

}

sub break_time
{
	my $num = $_[0];
	my $name = $_[1];
	my $job_id = $_[2];
	my $loc = $_[3];
	my $activity = $_[4];
	# print "$num, $name, $job_id, $loc, $activity <br/>";
	log_break_time ($num, $now);
	end_system_time ($num, "ALL", $now);
	update_system_elapsed_time ($num );
	log_in_screen_from_pm ();
}


